package org.feerepository.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.http.client.RequestException;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.HTMLTable.CellFormatter;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Hyperlink;
import org.feerepository.client.components.SearchPanel;
import org.feerepository.client.components.ServiceMapPanel;
import org.feerepository.client.controller.AreasController;
import org.feerepository.client.controller.ServiceListMapController;
import org.feerepository.client.request.HttpRequestFactory;
import org.feerepository.client.views.IAreasView;



public class FeeStructure implements EntryPoint 
{
	Application app = new Application();
	public void onModuleLoad() 
	{
		initTopPannel();
        try
        {
            initMainMenu();
        }
        catch(Exception ex)
        {

        }
		

		RootPanel rootPanel = RootPanel.get();
	
		//search panel configuration		
		Grid searchMenu = new Grid(1,4);
		CellFormatter formater = searchMenu.getCellFormatter();
		formater.setAlignment(0, 0, HasHorizontalAlignment.ALIGN_LEFT, HasVerticalAlignment.ALIGN_TOP);
		formater.setAlignment(0, 1, HasHorizontalAlignment.ALIGN_LEFT, HasVerticalAlignment.ALIGN_TOP);
		formater.setAlignment(0, 2, HasHorizontalAlignment.ALIGN_LEFT, HasVerticalAlignment.ALIGN_TOP);
		formater.setAlignment(0, 3, HasHorizontalAlignment.ALIGN_LEFT, HasVerticalAlignment.ALIGN_TOP);
		SearchPanel formatId = new SearchPanel("Format id");
		formatId.addItem("Sms");
		formatId.addItem("Dual");
		searchMenu.setWidget(0, 0, formatId);
		
		SearchPanel ssid = new SearchPanel("Settlement service");
		ssid.addItem("Iss");
		ssid.addItem("Eanss");
		ssid.addItem("Nnss");
		ssid.setWidth("150px");
		searchMenu.setWidget(0, 1, ssid);
		SearchPanel messageTypeCattegory = new SearchPanel("Message type cattegory");
		messageTypeCattegory.addItem("Pos");
		messageTypeCattegory.addItem("Aft");
		messageTypeCattegory.addItem("Original credit");
		messageTypeCattegory.addItem("Request for copy");
		messageTypeCattegory.setWidth("170px");
		searchMenu.setWidget(0, 2, messageTypeCattegory);
		
		SearchPanel product = new SearchPanel("Product");
		product.addItem("Business");
		product.addItem("Coroporate");
		product.addItem("Purchasing");
		product.addItem("Electron");
		searchMenu.setWidget(0, 3, product);
		app.setContentTitle(new HTML("<h3>Service filtering</h3>"));
        FlowPanel content = new FlowPanel();
        content.add(searchMenu);
        ServiceMapPanel services = new ServiceMapPanel();
        AppEventListerImpl.getInstance().addApplicationEventListener(services);
        ServiceListMapController.getInstance().addView(services);
        content.add(services);
		app.setContent(content);
		//split.setRightWidget(searchMenu);
	//	DecoratorPanel panel = new DecoratorPanel();
	//	panel.add(new HTML("test"));
		//split.setRightWidget(panel);
//end search menu	
		rootPanel.add(app);
	}
	private void initTopPannel()
	{
	//	app.addApplicationLink(ApplicationComponentFactory.getTopMenuOption("11.02.2009"));
	//	app.addApplicationLink(ApplicationComponentFactory.getTopMenuOption("About"));

        initTitlePanel();
	}

    private void initTitlePanel()
    {
        HorizontalPanel titlePanel = new HorizontalPanel();
        titlePanel.setWidth("100%");
        titlePanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
        titlePanel.add(ApplicationComponentFactory.getApplicationImages().logoImage().createImage());
        Grid title = new Grid(3,1);
        title.setCellPadding(0);
        title.setCellSpacing(0);
        title.setWidth("100%");
        title.getCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_RIGHT);
        title.getCellFormatter().setHorizontalAlignment(1, 0, HasHorizontalAlignment.ALIGN_RIGHT);
        title.getCellFormatter().setHorizontalAlignment(2, 0, HasHorizontalAlignment.ALIGN_RIGHT);
        title.setWidget(0, 0, new HTML("<h1>" + ApplicationComponentFactory.getConstantsSet().applicationTitle() +"</h1>"));
        title.setWidget(1, 0, new HTML("<h2>" + ApplicationComponentFactory.getConstantsSet().applicationSubTitle() +"</h2>"));
        
        HorizontalPanel links = new HorizontalPanel();
        links.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
        links.setStyleName("Application-links");
        links.add(ApplicationComponentFactory.getHiperlink("Home"));
        links.add(new HTML("&nbsp;|&nbsp;"));
        links.add(ApplicationComponentFactory.getHiperlink("Options"));
        links.add(new HTML("&nbsp;|&nbsp;"));
        links.add(ApplicationComponentFactory.getHiperlink("Customer Support"));
        links.add(new HTML("&nbsp;|&nbsp;"));
        links.add(ApplicationComponentFactory.getHiperlink("About"));


        
        title.setWidget(2, 0, links);
        titlePanel.add(title);
        app.setTitleWidget(titlePanel);
    }

 /**
  * Initialise the main menu
  * @throws com.google.gwt.http.client.RequestException
  */
	private void initMainMenu() throws RequestException
	{
        HttpRequestFactory factory = new HttpRequestFactory();
        AreasController.getInstance().addView((IAreasView)app.getMainMenu());
        factory.sendGetAreasRequest();
	}

}
